//
//  RootAnimationTableViewController.swift
//  SwitfTest
//
//  Created by runone02 on 2019/1/25.
//  Copyright © 2019年 liqiyun. All rights reserved.
//

import UIKit

class RootAnimationTableViewController: BaseTableViewController {

    let titleArr = ["UITableView状态切换效果",
                    "UITableView展开缩放动画",
                    "Cell点击动画",
                    "图片切换效果",
                    "UIScrollView视差效果动画",
                    "CATransfotm3D m34",
                    "图片碎片化mask动画",
                    "UILable混色显示",
                    "翻页效果",
                    "Easing-圆环动画",
                    "UITableView显示倒计时",
                    "AlertView的使用",
                    "系统字体列表"]
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.register(ListItemCell.self, forCellReuseIdentifier: "ListItemCell")
        //        tableView.rowHeight = 120
        loadMore()
    }
    
    private func loadMore(){
        //        //下拉刷新
        //        tableView.addPullRefresh({ [weak self] in
        //            DispatchQueue.main.asyncAfter(deadline: afterTime(3)) {
        //                self?.tableView.stopPullRefresh()
        //            }
        //        })
        //
        //        //加载更多
        //        tableView.addFooterRefresh(closure: {[weak self] in
        //            DispatchQueue.main.asyncAfter(deadline: afterTime(3)) {
        //                self?.tableView.stopPullRefresh()
        //            }
        //        })
        
        /////gif下拉刷新
        let arrIdle: NSMutableArray = NSMutableArray.init(capacity: 0)
        for i in 1...60 {
            let name = String.init(format: "dropdown_anim__000%zd", i)
            let image = UIImage.init(named: name)
            arrIdle.add(image!)
        }
        
        let arrRefresh: NSMutableArray = NSMutableArray.init(capacity: 0)
        for i in 1...3 {
            let name = String.init(format: "dropdown_loading_0%zd", i)
            let image = UIImage.init(named: name)
            arrRefresh.add(image!)
        }
        
        tableView.addGifPullRefresh(idleImages: arrIdle, refreshImages: arrRefresh, closure: { [weak self] in
            DispatchQueue.main.asyncAfter(deadline: afterTime(6)) {
                self?.tableView.stopPullRefresh()
            }
        })
        
        tableView.addFooterRefresh(closure: {[weak self] in
            DispatchQueue.main.asyncAfter(deadline: afterTime(3)) {
                self?.tableView.stopPullRefresh()
            }
        })
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Table view data source
    override func numberOfSections(in tableView: UITableView) -> Int {
        
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleArr.count
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier:"ListItemCell", for: indexPath) as! ListItemCell
        cell.titlelabel.text = titleArr[indexPath.row]

        return cell
    }
    
    
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if indexPath.row == 0 {            
            self.navigationController?.pushViewController(TableViewTapAnimationController(), animated: true)
        }else if indexPath.row == 1{
            self.navigationController?.pushViewController(HeaderViewTapAnimationController(), animated: true)
        }else if indexPath.row == 2 {
            self.navigationController?.pushViewController(TapCellAnimationController(), animated: true)
        }else if indexPath.row == 3 {
            self.navigationController?.pushViewController(LiveImageViewController(), animated: true)
        }else if indexPath.row == 4 {
            self.navigationController?.pushViewController(ScrollImageViewController(), animated: true)
        }else if indexPath.row == 5 {
            self.navigationController?.pushViewController(CATransform3DM34Controller(), animated: true)
        }else if indexPath.row == 6 {
            self.navigationController?.pushViewController(TransformFadeViewController(), animated: true)
        }else if indexPath.row == 7 {
            self.navigationController?.pushViewController(MixedColorProgressViewController(), animated: true)
        }else if indexPath.row == 8 {
            self.navigationController?.pushViewController(PageFlipEffectController(), animated: true)
        }else if indexPath.row == 9 {
            self.navigationController?.pushViewController(CircleAnimationViewController(), animated: true)
        }else if indexPath.row == 10 {
            self.navigationController?.pushViewController(CountDownTimerController(), animated: true)
        }else if indexPath.row == 11{
            self.navigationController?.pushViewController(AlertViewController(), animated: true)
        }else{
            self.navigationController?.pushViewController(SystemFontInfoController(), animated: true)
        }
    }
    
    

}
